<?php

namespace app\ad\controller;

use app\ad\controller\Common;
use think\Db;
use think\Session;

class Ad extends Common
{
    public $member = null;

    public function __construct($tokenaaa = '')
    {

        parent::__construct();

        $uid = Session::get('ad', 'ffxiangAd');
        $member = _user($uid['id']);
        $this->member = $member;
    }

    // 广告计划
    public function index()
    {
        $status = input('status');
        if ($status) {
            $map['status'] = $status;
        }
        $this->assign('status', $status);
        $search_name = input('param.search_name');
        // $mudi=input('param.mudi');
        // $this->assign('mudi',$mudi);
        // if($mudi){
        //     $map['mudi']=$mudi;
        // }
        if ($search_name) {
            //  $map['title']  = ['like','%'.$search_name.'%'];
            $map['name'] = ['like', '%' . $search_name . '%'];
        }

        $uid = $this->member['id'];
        $map['uid'] = $uid;
        $data = db('member_adjihua')->order('id')->where($map)->paginate('', false, ['query' => request()->param()])->each(function ($item, $key) {
            // $item['click'] = db('member_ad')->where('jid',$item['id'])->sum('click');
            // $item['show'] = db('member_ad')->where('jid',$item['id'])->sum('shows');
            // $item['cost'] = db('yaoqing_records')->where('jid',$item['id'])->where('time','between time',[date('Y-m-d'),date('Y-m-d',strtotime('+1day'))])->sum('money');
            // $item['danyuan'] = db('member_danyuan')->where('jid',$item['id'])->count();
            $item['ad'] = db('member_ad')->where('jid', $item['id'])->count();
            // $mudi=['0'=>'应用下载','1'=>'落地访问'];
            // // $status=['0'=>'关闭','1'=>'投放'];
            // $item['mudi']=$mudi[$item['mudi']];
            $status = ['0' => '关闭', '1' => '投放'];
            switch ($item['status']) {
                case '0':
                    $item['status'] = '<font color="#f00">' . $status[$item['status']] . '</font>';
                    break;
                case '1':
                    $item['status'] = '<font color="#1ab394">' . $status[$item['status']] . '</font>';
                    break;
            }
            // switch ($item['status']) {
            //     case '0':
            //        $item['status']='<font color="#f00">'.$status[$item['status']].'</font>';
            //         break;
            //     case '1':
            //        $item['status']='<font color="#1ab394">'.$status[$item['status']].'</font>';
            //         break;
            // }

            return $item;
        });
        $page = $data->render();
        $this->assign('data', $data);
        $this->assign('page', $page);
        return $this->fetch();
    }

    // 计划开关
    public function hidess()
    {
        if (request()->isAjax()) {
            $id = input('id') ? input('id') : '0';
            $type = input('type') ? input('type') : '0';
            $name = input('name') ? input('name') : '0';
            $uid = $this->member['id'];
            $text = ['0' => '<font color="#f00">关闭</font>', '1' => '<font color="#1ab394">投放</font>'];
            $uid = $this->member['id'];
            $texts = ['0' => '关闭', '1' => '投放'];
            if ($id) {
                $db = db('member_adjihua')->where(['id' => $id, 'uid' => $uid])->update(['status' => $type]);
                // var_dump($db);exit;
                if ($db === false) {
                    $data = ['err' => '修改失败'];
                } else {
                    // _records($uid,$texts[$type].'计划:('.$id.')'.$name,0,'ad');
                    $data = ['ret' => $text[$type]];
                }
            } else {
                $data = ['err' => 'GET值错误'];
            }
        } else {
            $data = ['err' => '提交错误'];
        }
        return $data;
    }

    //单元开关
    /*public function hide(){
        if(request()->isAjax()){
            $id=input('id') ? input('id'): '0';
            $type=input('type') ? input('type') : '0';

            $text=['0'=>'<font color="#f00">关闭</font>','1'=>'<font color="#1ab394">投放</font>'];
            $uid=$this->member['id'];
            $texts=['0'=>'关闭','1'=>'投放'];
            if($id){
                $db=db('member_danyuan')->where(['id'=>$id,'uid'=>$uid])->update(['status'=>$type]);
                // var_dump($db);exit;
                if($db===false){
                    $data=['err'=>'修改失败'];
                }else{
                    // _records($uid,$texts[$type].'单元:('.$id.')'.$name,0,'ad');
                    $data=['ret'=>$text[$type]];
                }
            }else{
                $data=['err'=>'GET值错误'];
            }
        }else{
            $data=['err'=>'提交错误'];
        }
        return $data;
    }*/

    // 创意开关
    public function hides()
    {
        if (request()->isAjax()) {
            $id = input('id') ? input('id') : '0';
            $type = input('type') ? input('type') : '0';

            $text = ['0' => '<font color="#f00">关闭</font>', '1' => '<font color="#1ab394">投放</font>'];
            $uid = $this->member['id'];
            $texts = ['0' => '关闭', '1' => '投放'];
            if ($id) {
                $check = db('member_ad')->where(['id' => $id, 'uid' => $uid])->value('check');
                if ($check == '1') {
                    $db = db('member_ad')->where(['id' => $id, 'uid' => $uid])->update(['status' => $type]);
                    // var_dump($db);exit;
                    if ($db === false) {
                        $data = ['err' => '修改失败'];
                    } else {
                        // _records($uid,$texts[$type].'创意:('.$id.')'.$name,0,'ad');
                        $data = ['ret' => $text[$type]];
                    }

                } else {
                    $data = ['err' => '当前广告创意审核未通过'];
                }


            } else {
                $data = ['err' => 'GET值错误'];
            }
        } else {
            $data = ['err' => '提交错误'];
        }
        return $data;
    }

    // 删除计划
    /*public function all(){
         if(request()->isAjax()){

             $post=input('post.');

             $type=input('type');
             // var_dump(input(''));exit;
             if(input('?post.id')){
                 $post=$post['id'];
                 if (is_array($post)) {
                     foreach ($post as $k => $v) {
                         $db=Db::execute("DELETE fx_member_adjihua ,fx_member_danyuan,fx_member_ad FROM fx_member_adjihua   LEFT OUTER JOIN  fx_member_danyuan  ON fx_member_danyuan.jid=fx_member_adjihua.id  LEFT OUTER JOIN  fx_member_ad  ON fx_member_ad.jid=fx_member_adjihua.id  WHERE  fx_member_adjihua.id =".$v['value']);
                     }
                     if($db){
                         $data=['ret'=>'删除成功'];
                     }else{
                         $data=['err'=>'删除失败'];
                     }
                 }else{
                     $data=['err'=>'参数有误'];
                 }


             }else{
                 $data=['err'=>'删除失败，未选中数据'];
             }
         }else{
             $data=['err'=>'提交类型错误'];
         }
         return $data;
     }*/

    // 添加广告计划
    public function add()
    {
        $id = input("id");

        if (request()->isAjax()) {
            $post = input('post.');
            // var_dump($post);exit;
            $time = date("Y-m-d H:i:s");
            if (strlen($post['name']) > 200) {
                $data = ['err' => '计划名超出范围'];
                return $data;
            }
            $uid = $this->member['id'];
            $post['uid'] = $uid;
            if ($post['name'] === '') {
                $post['name'] = '新的广告计划';
            }
            $post['max'] = $post['max'] * 100;
            if (!$id) {   // 添加数据
                $post['addtime'] = $time;
                $count = Db::name('member_adjihua')->where('uid', $uid)->count();
                if ($count >= 35) {
                    return ['err' => '计划数量不得超出35个'];
                }
                $db = Db::name('member_adjihua')->insert($post);
                if ($db) {
                    $data = ['ret' => '添加成功'];
                } else {
                    $data = ['err' => '添加失败'];
                }
            } else {      //修改数据

                $today = strtotime(date('Y-m-d'));
                if ($post['update_time'] > $today) {
                    $post['ci']++;
                    if ($post['ci'] > 10) {
                        return ['err' => '每个计划每天修改次数不超过10次'];
                    }
                } else {
                    $post['ci'] = 0;
                }
                //当日修改总次数
                $zci = Db::name('member_adjihua')->where(['uid' => $uid, 'update_time' => ['>', $today]])->sum('ci');
                if ($zci > 40) {
                    return ['err' => '每天计划累计修改次数不超过40次'];
                }
                $post['update_time'] = time();
                $ad = Db::name('member_ad')->where(['uid' => $uid, 'jid' => $id, 'status' => '1'])->find();

                if ($ad) {
                    //当天总消费
                    $zmoney = db('yaoqing_records')->where('jid', $id)->where('time', 'between time', [date('Y-m-d'), date('Y-m-d', strtotime('+1day'))])->sum('money');
                    if ($post['max']) {
                        if ($post['max'] < $zmoney) {
                            return ['err' => '日限额修改额度不能超过当日已消耗金额'];
                        }
                    }

                }
                $db = Db::name('member_adjihua')->where('id', $id)->update($post);
                if ($db) {
                    $data = ['ret' => '修改成功'];
                } else {
                    $data = ['err' => '修改失败'];
                }
            }

        } else {
            if ($id) {
                $name = Db::name('member_adjihua')->where('id', $id)->find();
                // var_dump($name);die();
                if ($name) {
                    $this->assign('name', $name);
                } else {
                    $data = ['err' => 'id参数错误'];
                }
            }
            $data = $this->fetch();
        }
        return $data;
    }

    // 添加广告单元
    /* public function dyadd(){
         $id=input("id");
         $uid=$this->member['id'];
         $jh=db('member_adjihua')->where('uid',$uid)->select();
         $this->assign('jh',$jh);
         if(request()->isAjax()){
             $post=input('post.');
             // var_dump($post);exit;
             $time=date("Y-m-d H:i:s");
             if (strlen($post['name'])>200) {
                 $data=['err'=>'单元名超出范围'];return $data;
             }
             if (!$post['price']) {
                 $data=['err'=>'出价不能为空'];return $data;
             }
             $post['uid']=$uid;
             $post['price']=$post['price']*100;
             if ($post['name']==='') {
                $post['name']='新的广告单元';
             }
             if(!$id){   // 添加数据
                 $post['addtime']=$time;
                 $db=Db::name('member_danyuan')->insert($post);
                 if($db){
                     $data=['ret'=>'添加成功'];
                 }else{
                     $data=['err'=>'添加失败'];
                 }
             }else{      //修改数据
                 $db=Db::name('member_danyuan')->where('id',$id)->update($post);
                 if($db){
                     $data=['ret'=>'修改成功'];
                 }else{
                     $data=['err'=>'修改失败'];
                 }
             }

         }else{
             $cpc=Db::name('member_danyuan')->where('pay','0')->order('price desc')->value('price');
             $cpm=Db::name('member_danyuan')->where('pay','1')->order('price desc')->value('price');
             if ($cpc===null) {
                 $cpc=100;
             }else{
                 $cpc+=50;
             }
             if ($cpm===null) {
                 $cpm=100;
             }else{
                 $cpm+=50;
             }
             $this->assign('cpm',$cpm);
             $this->assign('cpc',$cpc);
             if($id){
                 $name=Db::name('member_danyuan')->where('id',$id)->find();

                 // var_dump($name);die();
                 if($name){
                      $this->assign('name',$name);
                 }else{
                     $data=['err'=>'id参数错误'];
                 }
             }
             $data=$this->fetch();
         }
         return $data;
     }
     // 广告单元列表
     public function dylists(){
         $id=input("jid/d");
         if ($id) {
           $map['jid']=$id;
         }
         $jh=db('member_adjihua')->where('id',$id)->find();
         // if (!$jh) {
         //     $this->error('计划不存在','ad/index');
         // }
         $this->assign('jh',$jh['name']);

         $status=input('status');
         if($status){
             $map['status']=$status;
         }
         $this->assign('status',$status);
         $search_name=input('param.search_name');

         if($search_name){
           //  $map['title']  = ['like','%'.$search_name.'%'];
             $map['name']=['like','%'.$search_name.'%'];
         }

         $uid=$this->member['id'];
         $map['uid']=$uid;
         $data=db('member_danyuan')->order('id')->where($map)->paginate('',false,['query'=>request()->param()])->each(function($item, $key){
                 $item['ad'] = db('member_ad')->where(['dyid'=>$item['id'],'check'=>'1'])->count();
                 $status=['0'=>'关闭','1'=>'投放'];
                 switch ($item['status']) {
                     case '0':
                        $item['status']='<font color="#f00">'.$status[$item['status']].'</font>';
                         break;
                     case '1':
                        $item['status']='<font color="#1ab394">'.$status[$item['status']].'</font>';
                         break;
                 }
                 $type=['0'=>'信息流','1'=>'信息页','2'=>'互动广告','3'=>'横屏广告','4'=>'开屏广告'];
                 $item['type']=$type[$item['type']];
                 $pay=['0'=>'CPC','1'=>'CPM'];
                 $item['pay']=$pay[$item['pay']];
                 return $item;
             });
         $page = $data->render();
         $this->assign('data',$data);
         $this->assign('page', $page);
         return $this->fetch();
     }*/

    // 删除计划
    public function del()
    {
        if (request()->isAjax()) {
            $id = input('id');
            if ($id) {
                $db = Db::execute("DELETE fx_member_adjihua ,fx_member_ad FROM fx_member_adjihua  LEFT OUTER JOIN  fx_member_ad  ON fx_member_ad.jid=fx_member_adjihua.id  WHERE  fx_member_adjihua.id =$id");
                if ($db) {
                    $data = ['ret' => '删除成功'];
                } else {
                    $data = ['err' => '删除失败'];
                }
            } else {
                $data = ['err' => 'id参数错误'];
            }
        } else {
            $data = ['err' => '提交参数错误'];
        }
        return $data;
    }

    // 删除单元
    /*public function dydel()
    {
        if (request()->isAjax()) {
            $id = input('id');
            if ($id) {
                $db = Db::execute("DELETE fx_member_danyuan,fx_member_ad FROM fx_member_danyuan  LEFT OUTER JOIN  fx_member_ad  ON fx_member_ad.dyid=fx_member_danyuan.id  WHERE  fx_member_danyuan.id =$id");
                if ($db) {
                    $data = ['ret' => '删除成功'];
                } else {
                    $data = ['err' => '删除失败'];
                }
            } else {
                $data = ['err' => 'id参数错误'];
            }
        } else {
            $data = ['err' => '提交参数错误'];
        }
        return $data;
    }*/

    // 添加广告创意
    public function cyadd()
    {
        $id = input("id");
        $uid = $this->member['id'];
        // $jh=db('member_adjihua')->where('uid',$uid)->select();
        // $this->assign('jh',$jh);
        $dy = db('member_adjihua')->where('uid', $uid)->select();
        $this->assign('dy', $dy);
        if (request()->isAjax()) {
            $post = input('post.');
            if (strlen($post['name']) > 200) {
                $data = ['err' => '创意名超出范围'];
                return $data;
            }
            if (!$post['price']) {
                $data = ['err' => '出价不能为空'];
                return $data;
            }
            $post['price'] = $post['price'] * 100;
            switch ($post['type']) {
                case '0':
                    if (!$post['xiaotu']) {
                        $data = ['err' => '图片不能为空'];
                        return $data;
                    }
                    $post['img'] = $post['xiaotu'];
                    break;
                case '1':
                    if (!$post['zutu']) {
                        $data = ['err' => '图片不能为空'];
                        return $data;
                    }
                    $post['images'] = json_encode($post['zutu']);
                    break;
                case '2':
                    if (!$post['datu']) {
                        $data = ['err' => '图片不能为空'];
                        return $data;
                    }
                    $post['img'] = $post['datu'];
                    break;
                case '3':
                    if (!$post['hudong']) {
                        $data = ['err' => '图片不能为空'];
                        return $data;
                    }
                    $post['images'] = json_encode($post['hudong']);
                    break;
                case '4':
                    if (!$post['hengfu']) {
                        $data = ['err' => '图片不能为空'];
                        return $data;
                    }
                    $post['img'] = $post['hengfu'];
                    break;
                case '5':
                    if (!$post['kaiping']) {
                        $data = ['err' => '图片不能为空'];
                        return $data;
                    }
                    $post['img'] = $post['kaiping'];
                    break;
                case '6':
                    if (!$post['video'] || !$post['videoimg']) {
                        $data = ['err' => '请完善视频信息'];
                        return $data;
                    }
                    $post['video'] = $post['video'];
                    $post['videoimg'] = $post['videoimg'];
                    break;
            }
            unset($post['xiaotu']);
            unset($post['zutu']);
            unset($post['datu']);
            unset($post['hudong']);
            unset($post['hengfu']);
            unset($post['kaiping']);
            if ($post['name'] === '') {
                $post['name'] = '新的广告创意';
            }
            if (strpos($post['url'], 'http://') === false) {
                if (strpos($post['url'], 'https://') === false) {
                    $data = ['err' => '请填写完整有效的链接'];
                    return $data;
                }

            }
            $post['uid'] = $uid;
            if (!$id) {   // 添加数据
                $post['addtime'] = time();
                $db = Db::name('member_ad')->insert($post);
                if ($db) {
                    $data = ['ret' => '添加成功'];
                } else {
                    $data = ['err' => '添加失败'];
                }
            } else {      //修改数据
                $post['check'] = '0';
                $post['status'] = '0';
                $db = Db::name('member_ad')->where('id', $id)->update($post);
                if ($db === false) {
                    $data = ['err' => '修改失败'];
                } else {
                    $data = ['ret' => '修改成功'];

                }
            }

        } else {

            if ($id) {
                $name = Db::name('member_ad')->where('id', $id)->find();


                if ($name) {
                    switch ($name['type']) {
                        case '1':
                            $name['images'] = json_decode($name['images'], true);
                            break;
                        case '4':
                            $name['images'] = json_decode($name['images'], true);
                            break;
                    }
                    // var_dump($name);die();
                    $this->assign('name', $name);
                } else {
                    $data = ['err' => 'id参数错误'];
                }
            }
            $data = $this->fetch();
        }
        return $data;
    }

    // 广告创意列表
    public function cylists()
    {
        // $dyid=input("dyid/d");
        // if ($dyid) {
        //   $map['dyid']=$dyid;
        // }
        // $dy=db('member_danyuan')->where('id',$dyid)->find();
        // // if (!$jh) {
        // //     $this->error('计划不存在','ad/index');
        // // }
        // $this->assign('dy',$dy['name']);
        $jid = input("jid/d");
        if ($jid) {
            $map['jid'] = $jid;
        }
        $jh = db('member_adjihua')->where('id', $jid)->find();
        // if (!$jh) {
        //     $this->error('计划不存在','ad/index');
        // }
        $this->assign('jh', $jh['name']);
        $status = input('status');
        if ($status === '0') {
            $map['ad.status'] = $status;
        } elseif ($status === '1') {
            $map['ad.status'] = $status;
        }
        $this->assign('status', $status);
        $search_name = input('param.search_name');

        if ($search_name) {
            //  $map['title']  = ['like','%'.$search_name.'%'];
            $map['ad.name'] = ['like', '%' . $search_name . '%'];
        }

        $uid = $this->member['id'];
        $map['ad.uid'] = $uid;
        $data = db('member_ad ad')->field('ad.*,j.name jname,j.status jstatus')->join('member_adjihua j', 'j.id=ad.jid')->order('ad.id')->where($map)->paginate('', false, ['query' => request()->param()])->each(function ($item, $key) {
            $type = ['0' => '小图', '1' => '组图', '2' => '大图', '3' => '互动广告', '4' => '横幅广告', '5' => '开屏广告', '6' => '视频广告', '7' => '文字链广告'];
            $status = ['0' => '关闭', '1' => '投放'];
            switch ($item['status']) {
                case '0':
                    $item['status'] = '<font color="#f00">' . $status[$item['status']] . '</font>';
                    break;
                case '1':
                    $item['status'] = '<font color="#1ab394">' . $status[$item['status']] . '</font>';
                    break;
            }
            switch ($item['jstatus']) {
                case '0':
                    $item['jstatus'] = '<font color="#f00">' . $status[$item['jstatus']] . '</font>';
                    break;
                case '1':
                    $item['jstatus'] = '<font color="#1ab394">' . $status[$item['jstatus']] . '</font>';
                    break;
            }
            $check = ['0' => '审核中', '1' => '审核通过', '2' => '审核不通过'];
            switch ($item['check']) {
                case '2':
                    $item['checks'] = '<font color="#f00">' . $check[$item['check']] . '</font>';
                    break;
                case '1':
                    $item['checks'] = '<font color="#1ab394">' . $check[$item['check']] . '</font>';
                    break;
                case '0':
                    $item['checks'] = $check[$item['check']];
                    break;
            }
            $item['type'] = $type[$item['type']];
            return $item;
        });
        // var_dump($data);
        $page = $data->render();
        $this->assign('data', $data);
        $this->assign('page', $page);
        return $this->fetch();
    }

    // 删除创意
    public function cydel()
    {
        if (request()->isAjax()) {
            $id = input('id');
            if ($id) {
                $db = db('member_ad')->where('id', $id)->delete();
                if ($db) {
                    $data = ['ret' => '删除成功'];
                } else {
                    $data = ['err' => '删除失败'];
                }
            } else {
                $data = ['err' => 'id参数错误'];
            }
        } else {
            $data = ['err' => '提交参数错误'];
        }
        return $data;
    }

    // 删除分组
    /*public function appDel()
    {
        if (request()->isAjax()) {
            $id = input('id');
            if ($id) {
                $db = Db::name('adapp')->delete($id);
                if ($db) {
                    $data = ['ret' => '删除成功'];
                } else {
                    $data = ['err' => '删除失败'];
                }
            } else {
                $data = ['err' => 'id参数错误'];
            }
        } else {
            $data = ['err' => '提交参数错误'];
        }
        return $data;
    }

    public function app()
    {
        $data = Db::name('adapp')->order('id desc')->select();
        $this->assign('data', $data);
        return $this->fetch();
    }

    // 添加分组
    public function appAdd()
    {
        $id = input("id");
        if (request()->isAjax()) {
            $post = input('post.');
            if (!$id) {   // 添加数据
                $db = Db::name('adapp')->insert($post);
                if ($db) {
                    $data = ['ret' => '添加成功'];
                } else {
                    $data = ['err' => '添加失败'];
                }
            } else {      //修改数据
                $db = Db::name('adapp')->where('id', $id)->update($post);
                if ($db) {
                    $data = ['ret' => '修改成功'];
                } else {
                    $data = ['err' => '修改失败'];
                }
            }

        } else {
            if ($id) {
                $name = Db::name('adapp')->where('id', $id)->find();
                //var_dump($name);die();
                if ($name) {
                    $this->assign('name', $name);
                } else {
                    $data = ['err' => 'id参数错误'];
                }
            }
            $data = $this->fetch();
        }
        return $data;
    }

    function appconfig()
    {
        $config = config();
        $this->assign('cfg', $config['ad']);
        if (request()->isAjax()) {
            $post = input('post.');
            if ($post) {
                $data = $post;
                if ($data) {
                    $data = var_export($data, true);
                    $data = str_replace("array", "return", $data);
                    $data = str_replace("(", "[", $data);
                    $data = str_replace(")", "];", $data);
                    $data = "<?php\r\n" . $data;
                    file_put_contents(APP_PATH . 'extra/ad.php', print_r($data, true));
                    $data = ['ret' => '保存成功'];
                } else {
                    $data = ['err' => '保存失败'];
                }
            } else {
                $data = ['err' => '提交参数错误'];
            }
        } else {
            $data = $this->fetch();
        }
        return $data;
    }


    // 2018年2月6日 16:17:04 增加APP启动图广告
    public function appad()
    {
        $data = Db::name('appad')->order('id desc')->select();
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function appadd_q()
    {
        $id = input("id");
        if (request()->isAjax()) {
            $post = input('post.');
            $time = time();
            if (!$id) {   // 添加数据
                $titledb = Db::name('appad')->where('title', $post['title'])->find();
                if ($titledb) {
                    return ['err' => '分组标题已存在'];
                }
                $db = Db::name('appad')->insert($post);
                if ($db) {
                    $data = ['ret' => '添加成功'];
                } else {
                    $data = ['err' => '添加失败'];
                }
            } else {      //修改数据
                $db = Db::name('appad')->where('id', $id)->update($post);
                if ($db) {
                    $data = ['ret' => '修改成功'];
                } else {
                    $data = ['err' => '修改失败'];
                }
            }
        } else {
            if ($id) {
                $name = Db::name('appad')->where('id', $id)->find();
                if ($name) {
                    $this->assign('name', $name);
                } else {
                    $data = ['err' => 'id参数错误'];
                }
            }
            $data = $this->fetch();
        }
        return $data;

    }*/

    public function test()
    {
        $id = input('id/d');
        $name = Db::name('member_ad')->where('id', $id)->find();
        if ($name['img']) {
            $name['img'] = checkpath(_imgUrl('1') . $name['img']);
        }
        if ($name['images']) {
            $images = json_decode($name['images'], true);
            foreach ($images as $k => $v) {
                $name['imagesurl'][] = checkpath(_imgUrl('1') . $v);
            }
        }
        if ($name['videoimg']) {
            $name['videoimg'] = checkpath(_imgUrl('1') . $name['videoimg']);
        }
        if ($name['video']) {
            $name['video'] = checkpath(_imgUrl('1') . $name['video']);
        }
        // var_dump($name);
        $this->assign('name', $name);
        return $this->fetch();
    }


}
